<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>评论管理页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,+chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1">
    <script type="text/javascript" src="../../js/jquery-3.4.1.js"></script>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>


    <link rel="stylesheet" href="../../js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">

    <script src="../../js/jquery-3.4.1.js" charset="utf-8"></script>
    <script src="../../js/layui/layui.js" charset="utf-8"></script>


    <style type="text/css">

        .invisible {
            height: .5rem;
            top: .7rem;
        }
        .visible {
            height: .8rem;
            top: .55rem;
        }

        #updateReload{
            display: none;
        }
    </style>
</head>
<body>
<div class="demoTable">
    评论内容：
    <div class="layui-inline">
        <input class="layui-input" id="comContent" name="comContent">
    </div>
    评论时间：
    <div class="layui-inline">
        <input class="layui-input" id="comTime"  name="comTime" >
    </div>
    <button class="layui-btn layui-btn-primary" type="button" id="add">添加</button>
</div>
<table id="showUser" class="layui-table"
       lay-data="{width: 990,heigth: 'full-500',cellMinWidth: 80,url:'../../verycdComment/findAll', page:true, id:'idTest' }"
       lay-filter="demo" >
    <thead>
    <tr>
        <th lay-data="{field:'comContent', width:90, align:'center'}">评论内容</th>
        <th lay-data="{field:'comTime', width:90, align:'center'}">评论时间</th>
        <th lay-data="{field:'userId', width:200, align:'center'}">用户ID</th>
        <th lay-data="{field:'movieId', width:150, align:'center'}">电影ID</th>
        <th lay-data="{fixed:'right', width:120, align:'center', toolbar: '#barDemo'}">操作</th>
    </tr>
    </thead>
</table>

<script type="text/javascript">
    var user = null;
    $.fn.serializeObject = function () {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function () {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };
    layui.use(['form','laydate', 'laypage', 'layer', 'table', 'upload', 'element','tree'], function() {

        var form = layui.form
            ,laydate = layui.laydate //日期
            ,laypage = layui.laypage //分页
            ,layer = layui.layer //弹层
            ,table = layui.table //表格
            ,upload = layui.upload //上传
            ,element = layui.element; //元素操作

        $("#add").on('click',function () {
            layer.open({
                type: 2,
                area : ['65%' , '70%'],//弹出框大小
                shift:1,//弹出框动画效果
                content: ['commentForm.html','on'],
                success:function(layero,index) {
                    var body = layer.getChildFrame('body', index);//确定两个页面之间的父子关系

                    body.find("#closeUpdate").on("click",function () {
                        layer.close(index);
                    })
                }
            })
        })

        //监听表格复选框选择
        table.on('checkbox(demo)', function(obj) {
            console.log(obj)
        });

        //监听工具条
        table.on('tool(demo)', function(obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定删除该用户吗？', function(index) {
                    layer.close(index);
                    var id = data.comId;
                    var url = "../../verycdComment/delete";

                    $.ajax({
                        asyn : true,
                        type : "DELETE",
                        url : url,
                        data : {comId:id},
                        success : function(msg) {
                            if (msg.state == "1") {
                                layer.msg(msg.msg);
                                table.reload('idTest');
                            } else {
                                layer.msg(msg.msg);
                            }
                        },
                        error : function(fh) {
                            layer.msg(msg.msg);
                        }
                    },"json");
                });
            } else if (obj.event === 'edit') {
                var id=data.comId;00

                //使用jquery的ajax方式向后台提交数据
                var url = "../../verycdComment/selectOne/"+id;
                var da=null ;
                $.get(url,da,function(data){
                    user = data;
                        layer.open({
                        type: 2,
                        area : ['65%' , '70%'],//弹出框大小
                        shift:1,//弹出框动画效果
                        content: ['commentForm.html','on'], //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
                        success:function(layero,index){
                            var body = layer.getChildFrame('body',index);//确定两个页面之间的父子关系
                            var iframeWin = window[layero.find('iframe')[0]['name']];//子页面对象


                            body.find("#comId").val(data.comId);
                            body.find("#comContent").val(data.comContent);
                            body.find("#comTime").val(data.comTime);
                            body.find("#userId").val(data.userId);
                            body.find("#movieId").val(data.movieId);
                            body.find("#closeUpdate").on("click",function () {
                                user = null;
                                layer.close(index);
                            })
                        }
                    });

                },dataType="JSON");

            }
        });
        $("#query").on("click",function(){
            //执行重载
            table.reload('idTest', {
                where : {
                    'userName' : $("#userName").val(),
                    'userPhone' : $("#userPhone").val()
                },
                page : {
                    curr : 1
                }
            });
        });



    });



</script>
</body>
</html>